﻿using HuiZe.education.Resource.Controls;
using HuiZe.education.ViewModel;
using System.Linq;
using System.Windows;

namespace HuiZe.education.View
{
    /// <summary>
    /// NewGroupView.xaml 的交互逻辑
    /// </summary>
    public partial class EditFileGroupView : HuiZeWindow
    {
        int _file_id;
        int _group_id;
        MySpaceViewModel mySpaceViewModel = null;

        public EditFileGroupView(int id, int group_id)
        {
            InitializeComponent();
            this.MaxHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height + 10;
            this.MaxWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width + 10;
            _file_id = id;
            _group_id = group_id;
            Loaded += StudentView_Loaded;
        }

        public int Id { get; set; }
        public int groupId = 0;

        void YCButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = new bool?(false);
        }
        void StudentView_Loaded(object sender, RoutedEventArgs e)
        {
            mySpaceViewModel = DataContext as MySpaceViewModel;
            mySpaceViewModel.SelectedFileGroup = null;
            if (mySpaceViewModel.MyGroups != null && mySpaceViewModel.MyGroups.Count > 0)
            {
                var _group = mySpaceViewModel.MyGroups.Where(x => x.Id == _group_id).FirstOrDefault();
                if (_group != null)
                {
                    PART_CurrentGroup.Text = _group.GroupName;
                }
            }
        }
        void YCButton_Click_1(object sender, RoutedEventArgs e)
        {
            if (mySpaceViewModel.SelectedFileGroup == null)
            {
                mySpaceViewModel.ShowDialogView("请选择分组!");
                return;
            }

            bool _success = mySpaceViewModel.editFileGroup(_file_id, mySpaceViewModel.SelectedFileGroup.Id);
            if (_success)
                this.DialogResult = new bool?(true);
        }
    }
}
